package Stack;

import java.util.Stack;

public class NiBoLan {
    Stack<Integer> stack = new Stack<>();
    public int evalRPN(String[] tokens) {
        for (int i = 0; i < tokens.length; i++) {
            if(isOperation(tokens[i]) == false){
                stack.push(Integer.parseInt(tokens[i]));
            }else{
                int num2 = stack.pop();
                int num1 = stack.pop();
                switch (tokens[i]){
                    case "+":
                        stack.push(num1+num2);
                        break;
                    case "-":
                        stack.push(num1-num2);
                        break;
                    case "*":
                        stack.push(num1*num2);
                        break;
                    case "/":
                        stack.push(num1/num2);
                        break;
                }
            }
        }
        return stack.pop();
    }

    public boolean isOperation(String str){
        if(str.equals("+") || str.equals("-") ||str.equals("*") ||str.equals("/") ){
            return true;
        }else{
            return false;
        }
    }
    public static void main(String[] args) {

    }
}
